//
//  TradeListAlertTimeButton.swift
//  kxf
//
//  Created by Mac on 2024/3/20.
//

import Foundation
import UIKit

class TradeListAlertTimeButton: UIView {
    
    let selfHeight = kFitWidth(48)
    
    var timeString = "\(Date().todayDate)"
    var tapBlock:(()->())?
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: frame.origin.x, y: frame.origin.y, width: kFitWidth(152), height: selfHeight))
        self.backgroundColor = WHColor_16(colorStr: "F8F8F8")
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(4)
        self.clipsToBounds = true
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(tapAction))
        self.addGestureRecognizer(tap)
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.text = "\(Date().todayDate)"
        
        lab.adjustsFontSizeToFitWidth = true
        
        return lab
    }()
    lazy var arrowImg : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "login_arrow_img")
        
        return img
    }()
}

extension TradeListAlertTimeButton{
    @objc func tapAction() {
        if self.tapBlock != nil{
            self.tapBlock!()
        }
    }
}
extension TradeListAlertTimeButton{
    func initUI() {
        addSubview(arrowImg)
        addSubview(timeLabel)
        
        setConstrait()
    }
    func setConstrait() {
        arrowImg.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-20))
            make.width.height.equalTo(kFitWidth(22))
            make.centerY.lessThanOrEqualToSuperview()
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(10))
            make.right.equalTo(arrowImg.snp.left).offset(kFitWidth(-10))
            make.top.height.equalToSuperview()
        }
    }
}
